/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tigris.jasmincc.implementation;

import java.util.*;

import org.tigris.jasmincc.Production;
import org.tigris.jasmincc.framework.*;

/**
 * To switch between different production units.
 * 
 * @author Sam Huang
 * @deprecated
 */
@Deprecated
public class AnotherProductionFactory implements ProductionFactory {

	protected Map<String, String> alias = null;

	protected JavaCCModel javaccModel = null;

	protected Production defaultProduction = null;

	public AnotherProductionFactory() {
		// TODO move this part to the spring configuration file with alias
		// feature
		alias = new HashMap<String, String>();

		alias.put("TOKEN", "tokenDefinitionProduction");
		alias.put("PARSER_BEGIN", "parserClassDefinitionProduction");
		alias.put("TOKEN_MGR_DECLS", "tokenManagerDeclarationProduction");
		alias.put("SPECIAL_TOKEN", "specialTokenProduction");
		alias.put("MORE", "moreDefinitionProduction");
		alias.put("options", "optionsProduction");
		alias.put("SKIP", "skipDefinitionProduction");
		alias.put("dialectof", "dialectofProduction");
		alias.put("namespace", "namespaceDeclarationProduction");
		alias.put("java", "javaBlockProduction");
	}

	public Production getProduction(String token) throws Exception {
		Production production = null;

		String productionName = alias.get(token);
		if (productionName == null) {
			return defaultProduction;
		}
		try {
			production = (Production) SimpleObjectFactory.getInstance()
					.getBeanFactory().getBean(productionName);
		} catch (final Exception ex) {
			production = defaultProduction;
		}
		return production;
	}

	public void setDefaultProduction(Production production) {
		this.defaultProduction = production;
	}

}
